package com.dyna.core.utils;

import cn.hutool.core.util.StrUtil;
import com.dyna.constants.StringPool;
import com.dyna.constants.TokenConstant;

import java.util.Objects;

/**
 * @author zhoucaiwang
 * @date 2023/8/17
 */
public class TokenUtil {

    /**
     * 获取请求头中的Authorization
     */
    public static String getHeaderRequestToken() {
        String authorization = Objects.requireNonNull(WebUtil.getRequest()).getHeader(TokenConstant.AUTHORIZATION);
        if (StrUtil.isBlank(authorization)) {
            return StringPool.EMPTY;
        }
        return replaceBearer(authorization);
    }

    public static String replaceBearer(String authorization) {
        return authorization.replace(TokenConstant.BEARER_SPACE, StringPool.EMPTY);
    }

}
